<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script>

$(function()
{
	
});

function save_click()
{
	var obj = $.getObject("#div_form");
	var roleIds = new Array();
	
	$.each($("#div_form :checkbox:checked"), function(i, obj)
	{
		var $obj = $(obj);
		var type = $obj.attr("name");
		if (type == "roleId")
		{
			roleIds.push($obj.val());
		}
	});
	
	/* if (roleIds.length == 0)
	{
		$.errorAlert("至少选择一个角色");
		return;
	} */
	
	obj.roleIds = roleIds.join(",");
	$.simpleAjax("/base/user/user_role_save", obj, function(o)
	{
		$.successAlert("保存成功", "save_success()", 2000);
	});

}
function save_success()
{
	window.location = "${path}/base/user/user_list";
}



</script>

<div class="am-form am-form-horizontal am-cf am-margin" id="div_form">
<input type="hidden" name="userId" value="${model.id!}"/>

	<fieldset>
		<legend>修改账号角色－${model.nickname!}</legend>
		
		<#if roleMap??>
		<#list roleMap?keys as k>
		<div class="am-checkbox input_big"><label>${k!}</label></div>
		
		<#assign roleList=roleMap[k]! />
		<#if roleList??>
		<div class="am-form-group input_normal am-margin-left" >
		<#list roleList as vo>
			<label class="am-checkbox-inline">
				<input type="checkbox" name="roleId" value="${vo.id}" <#if vo.selected==0>checked</#if> /> ${vo.name!}
			</label>
		</#list>
		</div>
		</#if>
		
		</#list>
		</#if>
		
		<p>　</p>

		<div class="am-u-md-12 am-text-center div_btn">
			<a href="javascript:void(0)" onclick="save_click()" class="am-btn am-btn-primary am-radius">保存</a>
			<a href="javascript:void(0)" onclick="save_success()" class="am-btn am-btn-default am-radius am-margin-left">返回</a>
		</div>
	</fieldset>
</div>

<#include "/layout/footer.ftl" />